package io.cici.cc.mybatis.lite.sql_source.scripting.tag;

import io.cici.cc.mybatis.lite.sql_source.Context;

import java.util.List;


/**
 * @author huihui
 */
public class ChooseTag implements Tag {
    private final List<Tag> ifTagList;
    private final Tag defaultTag;


    public ChooseTag(List<Tag> ifTagList, Tag defaultTag) {
        this.ifTagList = ifTagList;
        this.defaultTag = defaultTag;
    }

    @Override
    public boolean apply(Context context) {
        for (Tag tag : ifTagList) {
            if (tag.apply(context)) {
                return true;
            }
        }
        if (defaultTag != null) {
            defaultTag.apply(context);
            return true;
        }
        return false;
    }
}
